<?php
function __autoload($class_name)
    {
        include $class_name . '.php';
    }
    $page = new page('Nacteni noveho clanku');
    $content = '';
    if(isset($_SESSION['user']) && $_SESSION['user']->validate())
    {
        //TODO: stranka pro registrovaneho uzivatele
        if(isset($_POST['loadArticle']))
        {
            //TODO: ulozeni clanku do databaze
            $Header = '';
            if(isset($_POST['header']))
                $header = $_POST['header'];
            if(isset($_POST['anotation']))
                $anotation = $_POST['anotation'];
            if(isset($_POST['article']))
                $article = $_POST['article'];
            $query = "INSERT INTO articles VALUES(
                null,
            '{$_SESSION['user']->getId()}',
            1,
            CURDATE(),
            0,
            0,
            '$header',
            '$anotation',
            '$article',
            '',
            1,
            1)";
            $conn = new dbConnection();
            $sql_result = $conn->db_query($query);
        }
       $content .= 'nahravani noveho clanku.';
       $content .= '<br />';
       
       $loadArticleForm = new form('loadArticle', $_SERVER['SCRIPT_NAME'], 'post', 'Nacist clanek: ',
               array(
                   new formTextArea('header', 'Nadpis: '),
                   new formTextArea('anotation','Anotace: '),
                   new formTextArea('article','Text clanku: '),
                   new formSubmit('Nahrat')
               ));
       $content .= $loadArticleForm->render();
    }else
    {
        //TODO: stranka pro hosta

        $content .= 'vitejte na strankach. Jste neprihlaseny uzivatel!';
        $content .= '<br />';
        $content .= 'prihlaste se!';
        $content .= '<br />';

    }
    echo $page->render($content);

?>
